class Solution(object):
    def hasCycle(self, head):
        """
        :type head: ListNode
        :rtype: bool
        """
        if not head:
            return False
        slow_node = head
        fast_node = head.next
        while slow_node and fast_node:
            if slow_node == fast_node:
                return True
            slow_node = slow_node.next
            if fast_node.next:
                fast_node = fast_node.next.next
            else:
                return False
        return False